﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Model;

namespace LOPA
{
    public partial class ProjectDetailsForm : Form{
        public static string projectName;

        public ProjectDetailsForm()
        {
            InitializeComponent();
            CenterToScreen();
            cbxHazopType.SelectedIndex = 0;
        }

        private void btnNext_Click(object sender, EventArgs e){
            if (tbxProjectName.Text.Equals("")){
                MessageBox.Show("项目名称未填写!");
                DialogResult = DialogResult.None;
                tbxProjectName.Focus();
                //  return;
            }
            else {
                if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\LOPA Project\\" + tbxProjectName.Text + "\\"))
                {
                    Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
                                              "\\LOPA Project\\" + tbxProjectName.Text + "\\");
                    projectName = tbxProjectName.Text;
                    MainForm.currentProject = projectName;
                    Program.Workspace.InitProjectInstance(tbxCompanyName.Text, projectName, tbxProjectLocation.Text, tbxTecUnit.Text, cbxHazopType.Text);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("该项目已经存在，不能重复创建!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    DialogResult = DialogResult.None;
                    tbxProjectName.Focus();
                }
                
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
